﻿/*
Typps HTML Editor for ASP.NET
FULL EDITION

Copyright (c) 2009 Alessandro Zifiglio, http://www.Typps.com
EMail: alessandro@Typps.com

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

Typps.MediaFrame=function (element) {
    Typps.MediaFrame.initializeBase(this,[element]);
    this._className=null;
    this._commandName=null;
    this._callbacks=null;
    this._display=null;
    this._shaderColor='#000';
    this._shaderOpacity=90;
    this._className=null;
    this._timeout=0;
    this._targetControlId=null;
    this._targetControlDelegate=null;
    this._popperId=null;
    this._targetControlActivationOn=null;
    this._formElementId=null;
    this._postbackAllFormData=null;
    this._updatePanelProgressId=null;
    this._mediaItems=null;
    this._thumbnails=null;
    this._mediaDisplayMode=0;
    this._pageSize=3;
    this._allowNavigation=true;
    this._allowPaging=true;
    this._allowSlideShow=true;
    this._moreButtonTitle=null;
    this._slideShowInterval=5000;
    this._autoStartSlideShow=false;
    this._loadingMessage=null;
    this._loadFailureMessage=null;
    this._loadFailureMediaUrl=null;
    this._minFrameWidth=300;
    this._minFrameHeight=300;
    this._largeMediaItem=0;
    this._dragSpeed=0;
    this._grabCursor=null;
    this._grabbingCursor=null;
    this._uniqueId=null;
    this._imageLoader=null;
    this._preloadAll=false;
    this._displayLoadingStatus=false;
    this._display=0;
    this._displayHeader=true;
    this._floatingNavigatorHeight='30px';
    this._enableEffects=true;
    this._slideEffectHorizontal=false;
}
Typps.MediaFrame.prototype = {
	get_nextMediaIndex: function () {
		if (this._mediaList.length > 0 && this._currentMediaIndex > -1) {
			if (this._currentMediaIndex == (this._mediaList.length - 1))
				return this._currentMediaIndex; //The end, sorry.
		}
		return ++this._currentMediaIndex;
	},
	get_previousMediaIndex: function () {
		var index = (this._currentMediaIndex == -1) ? this._currentMediaIndex++ : this._currentMediaIndex;
		if (index == 0)
			return index;
		return --this._currentMediaIndex;
	},
	get_isEOF: function () {
		return (this._currentMediaIndex == (this._mediaList.length - 1));
	},
	get_isBOF: function () {
		return (this._currentMediaIndex == 0);
	},
	get_isSlideShowActive: function () {
		return this._slideShowTimeout != null;
	},
	get_uniqueId: function () {
		return this._uniqueId;
	},
	set_uniqueId: function (value) {
		this._uniqueId = value;
	},
	get_updatePanelProgressId: function () {
		return this._updatePanelProgressId;
	},
	set_updatePanelProgressId: function (value) {
		this._updatePanelProgressId = value;
	},
	get_element: function () {
		return this._element;
	},
	get_className: function () {
		return (this._className == null) ? this.get_id() : this._className;
	},
	set_className: function (value) {
		this._className = value;
	},
	get_commandName: function () {
		return (this._commandName == null) ? '' : this._commandName;
	},
	set_commandName: function (value) {
		this._commandName = value;
	},
	get_slideShowInterval: function () {
		return this._slideShowInterval;
	},
	set_slideShowInterval: function (value) {
		this._slideShowInterval = value;
	},
	get_minFrameWidth: function () {
		return this._minFrameWidth;
	},
	set_minFrameWidth: function (value) {
		this._minFrameWidth = value;
	},
	get_minFrameHeight: function () {
		return this._minFrameHeight;
	},
	set_minFrameHeight: function (value) {
		this._minFrameHeight = value;
	},
	get_autoStartSlideShow: function () {
		return this._autoStartSlideShow;
	},
	set_autoStartSlideShow: function (value) {
		this._autoStartSlideShow = value;
	},
	get_targetControlActivationOn: function () {
		return (this._targetControlActivationOn == null) ? 'click' : this._targetControlActivationOn;
	},
	set_targetControlActivationOn: function (value) {
		this._targetControlActivationOn = value;
	},
	get_loadFailureMessage: function () {
		return this._loadFailureMessage;
	},
	set_loadFailureMessage: function (value) {
		this._loadFailureMessage = value;
	},
	get_loadingMessage: function () {
		return this._loadingMessage;
	},
	set_loadingMessage: function (value) {
		this._loadingMessage = value;
	},
	get_loadFailureMediaUrl: function () {
		return this._loadFailureMediaUrl;
	},
	set_loadFailureMediaUrl: function (value) {
		this._loadFailureMediaUrl = value;
	},
	get_callbacks: function () {
		return this._callbacks;
	},
	set_callbacks: function (value) {
		this._callbacks = value;
	},
	get_targetControlId: function () {
		return this._targetControlId;
	},
	set_targetControlId: function (value) {
		this._targetControlId = value;
	},
	get_display: function () {
		return (this._display == null) ? false : this._display;
	},
	set_display: function (value) {
		this._display = value;
	},
	get_className: function () {
		return this._className;
	},
	set_className: function (value) {
		this._className = value;
	},
	get_shaderColor: function () {
		return this._shaderColor;
	},
	set_shaderColor: function (value) {
		this._shaderColor = value;
	},
	get_shaderOpacity: function () {
		return this._shaderOpacity;
	},
	set_shaderOpacity: function (value) {
		this._shaderOpacity = value;
	},
	get_formElementId: function () {
		return this._formElementId;
	},
	set_formElementId: function (value) {
		this._formElementId = value;
	},
	get_postbackAllFormData: function () {
		return this._postbackAllFormData;
	},
	set_postbackAllFormData: function (value) {
		this._postbackAllFormData = value;
	},
	get_mediaItems: function () {
		return this._mediaItems;
	},
	set_mediaItems: function (value) {
		this._mediaItems = value;
	},
	get_thumbnails: function () {
		return this._thumbnails;
	},
	set_thumbnails: function (value) {
		this._thumbnails = value;
	},
	get_mediaDisplayMode: function () {
		return this._mediaDisplayMode;
	},
	set_mediaDisplayMode: function (value) {
		this._mediaDisplayMode = value;
	},
	get_pageSize: function () {
		return this._pageSize;
	},
	set_pageSize: function (value) {
		this._pageSize = value;
	},
	get_allowNavigation: function () {
		return this._allowNavigation;
	},
	set_allowNavigation: function (value) {
		this._allowNavigation = value;
	},
	get_allowPaging: function () {
		return this._allowPaging;
	},
	set_allowPaging: function (value) {
		this._allowPaging = value;
	},
	get_allowSlideShow: function () {
		return this._allowSlideShow;
	},
	set_allowSlideShow: function (value) {
		this._allowSlideShow = value;
	},
	get_largeMediaItem: function () {
		return this._largeMediaItem;
	},
	set_largeMediaItem: function (value) {
		this._largeMediaItem = value;
	},
	get_moreButtonTitle: function () {
		return this._moreButtonTitle;
	},
	set_moreButtonTitle: function (value) {
		this._moreButtonTitle = value;
	},
	get_grabbingCursor: function () {
		return this._grabbingCursor;
	},
	set_grabbingCursor: function (value) {
		this._grabbingCursor = value;
	},
	get_grabCursor: function () {
		return this._grabCursor;
	},
	set_grabCursor: function (value) {
		this._grabCursor = value;
	},
	get_dragSpeed: function () {
		return this._dragSpeed;
	},
	set_dragSpeed: function (value) {
		this._dragSpeed = value;
	},
	get_preloadAll: function () {
		return this._preloadAll;
	},
	set_preloadAll: function (value) {
		this._preloadAll = value;
	},
	get_displayLoadingStatus: function () {
		return this._displayLoadingStatus;
	},
	set_displayLoadingStatus: function (value) {
		this._displayLoadingStatus = value;
	},
	get_display: function () {
		return this._display;
	},
	set_display: function (value) {
		this._display = value;
	},
	get_displayHeader: function () {
		return this._displayHeader;
	},
	set_displayHeader: function (value) {
		this._displayHeader = value;
	},
	get_floatingNavigatorHeight: function () {
		return this._floatingNavigatorHeight;
	},
	set_floatingNavigatorHeight: function (value) {
		this._floatingNavigatorHeight = value;
	},
	get_enableEffects: function () {
		return this._enableEffects;
	},
	set_enableEffects: function (value) {
		this._enableEffects = value;
	},
	get_slideEffectHorizontal: function () {
		return this._slideEffectHorizontal;
	},
	set_slideEffectHorizontal: function (value) {
		this._slideEffectHorizontal = value;
	},
	add_targetControlClick: function (handler) {
		this.get_events().addHandler('targetcontrolclick', handler);
	},
	remove_targetControlClick: function (handler) {
		this.get_events().removeHandler('targetcontrolclick', handler);
	},
	add_thumbnailItemClick: function (handler) {
		this.get_events().addHandler('thumbnailclick', handler);
	},
	remove_thumbnailItemClick: function (handler) {
		this.get_events().removeHandler('thumbnailclick', handler);
	},
	add_pagerButton: function (handler) {
		this.get_events().addHandler('pager', handler);
	},
	remove_pagerButton: function (handler) {
		this.get_events().removeHandler('pager', handler);
	},
	add_mediaElementClicked: function (handler) {
		this.get_events().addHandler('mediaelementclicked', handler);
	},
	remove_mediaElementClicked: function (handler) {
		this.get_events().removeHandler('mediaelementclicked', handler);
	},
	add_mediaElementLoaded: function (handler) {
		this.get_events().addHandler('mediaelementloaded', handler);
	},
	remove_mediaElementLoaded: function (handler) {
		this.get_events().removeHandler('mediaelementloaded', handler);
	},
	add_mediaElementOnloadError: function (handler) {
		this.get_events().addHandler('mediaelementonloaderror', handler);
	},
	remove_mediaElementOnloadError: function (handler) {
		this.get_events().removeHandler('mediaelementonloaderror', handler);
	},
	add_mediaPreload: function (handler) {
		this.get_events().addHandler('mediapreload', handler);
	},
	remove_mediaPreload: function (handler) {
		this.get_events().removeHandler('mediapreload', handler);
	},
	add_mediaPreloadOnError: function (handler) {
		this.get_events().addHandler('mediapreloadonerror', handler);
	},
	remove_mediaPreloadOnError: function (handler) {
		this.get_events().removeHandler('mediapreloadonerror', handler);
	},
	add_closeButton: function (handler) {
		this.get_events().addHandler('close', handler);
	},
	remove_closeButton: function (handler) {
		this.get_events().removeHandler('close', handler);
	},
	add_firstButton: function (handler) {
		this.get_events().addHandler('first', handler);
	},
	remove_firstButton: function (handler) {
		this.get_events().removeHandler('first', handler);
	},
	add_lastButton: function (handler) {
		this.get_events().addHandler('last', handler);
	},
	remove_lastButton: function (handler) {
		this.get_events().removeHandler('last', handler);
	},
	add_previousButton: function (handler) {
		this.get_events().addHandler('previous', handler);
	},
	remove_previousButton: function (handler) {
		this.get_events().removeHandler('previous', handler);
	},
	add_nextButton: function (handler) {
		this.get_events().addHandler('next', handler);
	},
	remove_nextButton: function (handler) {
		this.get_events().removeHandler('next', handler);
	},
	add_slideShowButton: function (handler) {
		this.get_events().addHandler('slideshow', handler);
	},
	remove_slideShowButton: function (handler) {
		this.get_events().removeHandler('slideshow', handler);
	},
	add_pauseButton: function (handler) {
		this.get_events().addHandler('pause', handler);
	},
	remove_pauseButton: function (handler) {
		this.get_events().removeHandler('pause', handler);
	},
	add_onMediaItemDisplay: function (handler) {
		this.get_events().addHandler('onmediaitemdisplay', handler);
	},
	remove_onMediaItemDisplay: function (handler) {
		this.get_events().removeHandler('onmediaitemdisplay', handler);
	},
	add_onMediaItemShow: function (handler) {
		this.get_events().addHandler('onmediaitemshow', handler);
	},
	remove_onMediaItemShow: function (handler) {
		this.get_events().removeHandler('onmediaitemshow', handler);
	},
	add_beginWebRequest: function (handler) {
		this.get_events().addHandler('beginWebRequest', handler);
	},
	remove_beginWebRequest: function (handler) {
		this.get_events().removeHandler('beginWebRequest', handler);
	},
	add_endWebRequest: function (handler) {
		this.get_events().addHandler('endWebRequest', handler);
	},
	remove_endWebRequest: function (handler) {
		this.get_events().removeHandler('endWebRequest', handler);
	},
	add_popperAction: function (handler) {
		this.get_events().addHandler('popper', handler);
	},
	remove_popperAction: function (handler) {
		this.get_events().removeHandler('popper', handler);
	},
	add_onShowLoadingStatus: function (handler) {
		this.get_events().addHandler('onshowloadingstatus', handler);
	},
	remove_onShowLoadingStatus: function (handler) {
		this.get_events().removeHandler('onshowloadingstatus', handler);
	},
	add_onHideLoadingStatus: function (handler) {
		this.get_events().addHandler('onhideloadingstatus', handler);
	},
	remove_onHideLoadingStatus: function (handler) {
		this.get_events().removeHandler('onhideloadingstatus', handler);
	},
	add_onRepositionLoadingStatus: function (handler) {
		this.get_events().addHandler('onrepositionloadingstatus', handler);
	},
	remove_onRepositionLoadingStatus: function (handler) {
		this.get_events().removeHandler('onrepositionloadingstatus', handler);
	},
	dispose: function () {
		var num1 = null;
		if (this._closeButtonClickedDelegate) {
			if (this._closeButton != null)
				Sys.UI.DomEvent.removeHandler(this._closeButton, 'click', this._closeButtonClickedDelegate);
			delete this._closeButtonClickedDelegate;
		}
		if (this._firstButtonClickedDelegate) {
			if (this._firstButton != null)
				Sys.UI.DomEvent.removeHandler(this._firstButton, 'click', this._firstButtonClickedDelegate);
			delete this._firstButtonClickedDelegate;
		}
		if (this._lastButtonClickedDelegate) {
			if (this._lastButton != null)
				Sys.UI.DomEvent.removeHandler(this._lastButton, 'click', this._lastButtonClickedDelegate);
			delete this._lastButtonClickedDelegate;
		}
		if (this._slideShowButtonClickedDelegate != null) {
			Sys.UI.DomEvent.removeHandler(this._slideShowButton, 'click', this._slideShowButtonClickedDelegate);
			delete this._slideShowButtonClickedDelegate;
		}
		if (this._pauseButtonClickedDelegate != null) {
			Sys.UI.DomEvent.removeHandler(this._pauseButton, 'click', this._pauseButtonClickedDelegate);
			delete this._pauseButtonClickedDelegate;
		}
		if (this._previousButtonClickedDelegate != null) {
			Sys.UI.DomEvent.removeHandler(this._previousButton, 'click', this._previousButtonClickedDelegate);
			delete this._previousButtonClickedDelegate;
		}
		if (this._nextButtonClickedDelegate != null) {
			Sys.UI.DomEvent.removeHandler(this._nextButton, 'click', this._nextButtonClickedDelegate);
			delete this._nextButtonClickedDelegate;
		}
		this._removeHandlerPagerButtons();
		this._removeHandlerMediaListItems();

		if (this._thumbnailClickedDelegate != null &&
                (this._thumbnailList != null && this._thumbnailList.length > 0)) {
			for (num1 = 0; num1 < this._thumbnailList.length; num1++)
				Sys.UI.DomEvent.removeHandler(this._thumbnailList[num1], 'click', this._thumbnailClickedDelegate);
			delete this._thumbnailClickedDelegate;
		}

		if (this.windowMediaFrame)
			delete this.windowMediaFrame;

		if (this._targetControlDelegate) {
			if (this._targetControlId != null) {
				var targetControl = $get(this._targetControlId);
				if (targetControl != null)
					Sys.UI.DomEvent.removeHandler(targetControl, this._targetControlActivationOn, this._targetControlDelegate);
			}
		}
		delete this._targetControlDelegate;
		Typps.MediaFrame.callBaseMethod(this, 'dispose');
	},
	clearMediaItems: function () {
		this._currentMediaIndex = -1;
		this._removeHandlerPagerButtons();
		this._removeHandlerMediaListItems();
		this.set_mediaItems(null);
	},
	_removeHandlerPagerButtons: function () {
		if ((this._pagerButtonsList != null && this._pagerButtonsList.length > 0) &&
            this._pagerButtonClickedDelegate != null) {
			var length = this._pagerButtonsList.length;
			for (var num1 = length; num1 > 0; num1--) {
				var a = this._pagerButtonsList.pop();
				Sys.UI.DomEvent.removeHandler(a, 'click', this._pagerButtonClickedDelegate);
				if (a.parentNode != null)
					a.parentNode.removeChild(a);
			}
			if (length > this._pageSize) {
				Sys.UI.DomEvent.removeHandler(this._moreButtonForward, 'click', this._pagerButtonClickedDelegate);
				Sys.UI.DomEvent.removeHandler(this._moreButtonBackward, 'click', this._pagerButtonClickedDelegate);
			}
		}
		delete this._pagerButtonsList;
		this._pagerButtonsList = null;
		delete this._pagerButtonClickedDelegate;
		this._pagerButtonClickedDelegate = null;
	},
	_removeHandlerMediaListItems: function () {
		if (this._mediaList != null && this._mediaList.length > 0) {
			var length = this._mediaList.length;
			for (var num1 = length; num1 > 0; num1--) {
				var img = this._mediaList.pop();
				if (this._mediaElementClickedDelegate)
					Sys.UI.DomEvent.removeHandler(img, 'click', this._mediaElementClickedDelegate);
				if (this._mediaElementLoadedDelegate)
					Sys.UI.DomEvent.removeHandler(img, 'load', this._mediaElementLoadedDelegate);
				if (this._mediaElementOnErrorDelegate)
					img.onerror = null;
				if (img.isDraggable) {
					if (this._mouseDownDelegate)
						Sys.UI.DomEvent.removeHandler(img, 'mousedown', this._mouseDownDelegate);
					if (this._mouseUpDelegate1)
						Sys.UI.DomEvent.removeHandler(img, 'mouseup', this._mouseUpDelegate1);
				}
				if (img.parentNode != null)
					img.parentNode.removeChild(img);
			}
		}
		delete this._mediaList;
		this._mediaList = null;

		delete this._mediaElementClickedDelegate;
		this._mediaElementClickedDelegate = null;

		delete this._mediaElementLoadedDelegate;
		this._mediaElementLoadedDelegate = null;

		delete this._mediaElementOnErrorDelegate;
		this._mediaElementOnErrorDelegate = null;

		delete this._mouseDownDelegate;
		this._mouseDownDelegate = null;

		delete this._mouseUpDelegate1;
		this._mouseUpDelegate1 = null;
	},
	initialize: function () {
		Typps.MediaFrame.callBaseMethod(this, 'initialize');
		this._imageLoader = new Spry.Utils.ImageLoader();
		this._isIE = (Sys.Browser.agent == Sys.Browser.InternetExplorer && Sys.Browser.version < 9);
		this._updatePanelProgress = null;
		this._beginRequestHandlerDelegate = null;
		this._endRequestHandlerDelegate = null;
		this._closeButtonClickedDelegate = null;
		this._firstButtonClickedDelegate = null;
		this._lastButtonClickedDelegate = null;
		this._previousButtonClickedDelegate = null;
		this._nextButtonClickedDelegate = null;
		this._slideShowButtonClickedDelegate = null;
		this._pauseButtonClickedDelegate = null;
		this._pagerButtonClickedDelegate = null;
		this._thumbnailClickedDelegate = null;
		this._mediaElementClickedDelegate = null;
		this._mediaElementLoadedDelegate = null;
		this._mediaElementOnErrorDelegate = null;
		this._mouseDownDelegate = null;
		this._mouseMoveDelegate = null;
		this._mouseUpDelegate1 = null;
		this._mouseUpDelegate2 = null;
		this._caption = null;
		this._totalPages = 0;
		this._currentMediaIndex = -1;
		this._moreButtonBackward = null;
		this._moreButtonForward = null;
		this.windowMediaFrame = null;
		this._slideShowTimeout = null;
		this._header = null;
		this._contentContainer = null;
		this._innerBlock = null;
		this._footer = null;
		this._pagerButtons = null;
		this._previousButton = null;
		this._nextButton = null;
		this._slideShowButton = null;
		this._pauseButton = null;
		this._paused = false;
		this._closeButton = null;
		this._firstButton = null;
		this._lastButton = null;
		this._selects = null;
		this._loadingStatus = null;
		this._startMouseX = 0;
		this._startMouseY = 0;
		this._startX = 0;
		this._startY = 0;
		this._clientX = null;
		this._clientY = null;
		this._thumbnailList = [];
		this._mediaList = null;
		this._mediaListUrls = null;
		this._pagerButtonsList = null;
		this._selectedPageClassName = 'selectedpagerbutton';
		this._pendingPreloadList = [];
		this._preloadedMediaList = [];
		this._pendingNavigatorMethods = [];
		this._floatingNav = null;

		this._form = Typps.Utility.getForm(this._formElementId);

		this._isDisplayStatic = (this._display == 1);
		this._effectsCluster = null;
		this._afterEffects = [];

		if (!this._isDisplayStatic)
			this._slideEffectHorizontal = false; /*we support horizontal only in static mode*/

		if (this._updatePanelProgress === null && this._updatePanelProgressId != null)
			this._updatePanelProgress = $find(this._updatePanelProgressId);

		if (this._display == Typps.MediaFrame.Position.ModalPopup) {
			this._onResizeHandlerDelegate = Function.createDelegate(this, this._onResizeHandler);
			Sys.UI.DomEvent.addHandler(window, 'resize', this._onResizeHandlerDelegate);

			this._onScrollHandlerDelegate = Function.createDelegate(this, this._onScrollHandler);
			Sys.UI.DomEvent.addHandler(window, 'scroll', this._onScrollHandlerDelegate);

			this._onInit(false);
		}
		else {
			this._startMediaFrame();
		}
	},
	initializeMediaFrame: function () {
		this._onInit(true);
	},
	_onInit: function (buildPager) {
		if (this._targetControlId != null) {
			var targetControl = $get(this._targetControlId);
			if (targetControl != null) {
				if (this._targetControlDelegate === null)
					this._targetControlDelegate = Function.createDelegate(this, this._targetControlHandler);
				Sys.UI.DomEvent.addHandler(targetControl, this._targetControlActivationOn, this._targetControlDelegate);
			}
		}
		if (this._thumbnails != null && this._thumbnails.length > 0)
			this._createThumbnailTargets();
		this._createMediaElements();
		if (buildPager)
			this._createPagerButtons();
	},
	_createMediaElements: function () {
		if (this._pagerButtonClickedDelegate == null)
			this._pagerButtonClickedDelegate = Function.createDelegate(this, this._pagerButtonClickedHandler);
		if (this._mediaElementLoadedDelegate == null)
			this._mediaElementLoadedDelegate = Function.createDelegate(this, this._mediaElementLoadedHandler);
		var context = this;
		if (this._mediaElementOnErrorDelegate == null)
			this._mediaElementOnErrorDelegate = Function.createCallback(context._mediaElementOnErrorHandler, context);

		if (this._mediaDisplayMode == 0) {
			if (this._mediaElementClickedDelegate == null)
				this._mediaElementClickedDelegate = Function.createDelegate(this, this._mediaElementClickedHandler);
		}
		this._mediaList = [];
		this._mediaListUrls = [];

		this._totalPages = (this._mediaItems == null) ? 0 : this._mediaItems.length;
		for (var index in this._mediaItems) {
			var item = this._mediaItems[index];
			if (this._mediaDisplayMode == 0)//images
			{
				var img = document.createElement('img');
				img.id = this.get_id() + '_img' + index;
				Array.add(this._mediaListUrls, item.url);
				img.title = item.title;
				img.alt = item.title;
				img.style.display = 'none';
				img.setAttribute('value', item.value);
				img.setAttribute('currentindex', index);
				if (this._isDisplayStatic) {
					img.style.width = this._minFrameWidth + 'px';
					img.style.height = this._minFrameHeight + 'px';
				}
				Sys.UI.DomEvent.addHandler(img, 'click', this._mediaElementClickedDelegate);
				Sys.UI.DomEvent.addHandler(img, 'load', this._mediaElementLoadedDelegate);
				img.onerror = this._mediaElementOnErrorDelegate;
				Array.add(this._mediaList, img);
			}
		}
	},
	_getIndexByMediaItemId: function (id) {
		for (var index in this._mediaList) {
			var item = this._mediaList[index];
			if (item.id == id)
				return index;
		}
		return -1;
	},
	_createThumbnailTargets: function () {
		if (this._thumbnailClickedDelegate == null)
			this._thumbnailClickedDelegate = Function.createDelegate(this, this._thumbnailClickedHandler);
		for (var index in this._thumbnails) {
			var item = this._thumbnails[index];
			var elem = $get(item.clientId);
			if (elem != null) {
				elem.setAttribute('value', item.value);
				Sys.UI.DomEvent.addHandler(elem, 'click', this._thumbnailClickedDelegate);
				Array.add(this._thumbnailList, elem);
			}
		}
	},
	_startMediaFrame: function () {
		if (!this._isDisplayStatic) return;

		if (this._thumbnails.length > 0)
			this._createThumbnailTargets();
		this._createMediaElements();
		//display mode is static, means we already have markup
		this._createMediaFrame(null, null);
	},
	_createMediaFrame: function (markup, pageIndex) {
		var id = this.get_id();
		if (markup != null) {
			/*fix hasLayout bug in IE6/7 otherwise the element will expand full width;
			a table is a good fix because tables have layout by default*/
			//if(this._isIE&&Sys.Browser.version<8)
			markup = String.format('<table id="{0}_windowcontainer"><tr><td>{1}</td></tr></table>', id, markup);

			var container = document.createElement('div');
			this.windowMediaFrame = Typps.Utility.getAdjacentHTML(markup, container).firstChild;

			container = document.body;
			container.appendChild(this.windowMediaFrame);
		}
		else {
			this.windowMediaFrame = $get(id + '_window');
		}
		var allowPaging = ((this._allowNavigation && this._totalPages > 1) && this._allowPaging);

		if (this._closeButtonClickedDelegate === null)
			this._closeButtonClickedDelegate = Function.createDelegate(this, this._closeButtonClickedHandler);

		if ((this._firstButtonClickedDelegate === null && allowPaging) && (this._pageSize < this._totalPages))
			this._firstButtonClickedDelegate = Function.createDelegate(this, this._firstButtonClickedHandler);

		if ((this._lastButtonClickedDelegate === null && allowPaging) && (this._pageSize < this._totalPages))
			this._lastButtonClickedDelegate = Function.createDelegate(this, this._lastButtonClickedHandler);

		if (this._previousButtonClickedDelegate === null && allowPaging)
			this._previousButtonClickedDelegate = Function.createDelegate(this, this._previousButtonClickedHandler);

		if (this._nextButtonClickedDelegate === null && allowPaging)
			this._nextButtonClickedDelegate = Function.createDelegate(this, this._nextButtonClickedHandler);

		if (this._slideShowButtonClickedDelegate === null && this._allowSlideShow)
			this._slideShowButtonClickedDelegate = Function.createDelegate(this, this._slideShowButtonClickedHandler);

		if (this._pauseButtonClickedDelegate === null && this._allowSlideShow)
			this._pauseButtonClickedDelegate = Function.createDelegate(this, this._pauseButtonClickedHandler);

		this._contentContainer = $get(id + '_content');
		this._innerBlock = $get(id + '_innerblock');
		this._caption = $get(id + '_capt');
		this._pagerButtons = $get(id + '_pagerbuttons');
		this._firstButton = $get(id + '_firstbutton');
		this._previousButton = $get(id + '_prevbutton');
		this._nextButton = $get(id + '_nextbutton');
		this._lastButton = $get(id + '_lastbutton');
		this._slideShowButton = $get(id + '_slideshowbutton');
		this._pauseButton = $get(id + '_pausebutton');
		this._closeButton = $get(id + '_closebutton');
		this._header = $get(id + '_header');
		this._footer = $get(id + '_footer');
		this._loadingStatus = $get(id + '_loadingstatus');
		if (this._header != null) {
			this._addCssClass(this._header, 'header');
			if (this._enableEffects)
				this._header.style.visibility = 'hidden';
			this._header.style.width = '100%';
		}
		if (this._caption != null)
			this._addCssClass(this._caption, 'headercaption');

		if (this._footer != null)
			this._addCssClass(this._footer, 'footer');

		this._moreButtonForward = $get(id + '_moreforward');
		this._moreButtonBackward = $get(id + '_morebackward');
		if (this._moreButtonForward != null) {
			this._moreButtonForward.title = this._moreButtonTitle;
			this._addCssClass(this._moreButtonForward, 'pagerbutton');
			this._moreButtonForward.style.display = 'none';
		}
		if (this._moreButtonBackward != null) {
			this._moreButtonBackward.title = this._moreButtonTitle;
			this._addCssClass(this._moreButtonBackward, 'pagerbutton');
			this._moreButtonBackward.style.display = 'none';
		}

		if (this._contentContainer != null)
			this._addCssClass(this._contentContainer, 'body');

		if (this._closeButton != null) {
			this._addCssClass(this._closeButton, 'closebutton');
			this._closeButton.innerHTML = '&nbsp;';
			Sys.UI.DomEvent.addHandler(this._closeButton, 'click', this._closeButtonClickedDelegate);
		}

		if (this._firstButtonClickedDelegate != null) {
			this._addCssClass(this._firstButton, 'firstbutton');
			this._firstButton.innerHTML = '&nbsp;';
			Sys.UI.DomEvent.addHandler(this._firstButton, 'click', this._firstButtonClickedDelegate);
		}
		else {
			this._firstButton.style.display = 'none';
		}

		if (this._lastButtonClickedDelegate != null) {
			this._addCssClass(this._lastButton, 'lastbutton');
			this._lastButton.innerHTML = '&nbsp;';
			Sys.UI.DomEvent.addHandler(this._lastButton, 'click', this._lastButtonClickedDelegate);
		}
		else {
			this._lastButton.style.display = 'none';
		}

		if (this._previousButtonClickedDelegate != null) {
			this._addCssClass(this._previousButton, 'previousbutton');
			this._previousButton.innerHTML = '&nbsp;';
			Sys.UI.DomEvent.addHandler(this._previousButton, 'click', this._previousButtonClickedDelegate);
		}
		else {
			this._previousButton.style.display = 'none';
		}

		if (this._nextButtonClickedDelegate != null) {
			this._addCssClass(this._nextButton, 'nextbutton');
			this._nextButton.innerHTML = '&nbsp;';
			Sys.UI.DomEvent.addHandler(this._nextButton, 'click', this._nextButtonClickedDelegate);
		}
		else {
			this._nextButton.style.display = 'none';
		}

		if (this._slideShowButtonClickedDelegate != null) {
			this._addCssClass(this._slideShowButton, 'slideshowbutton');
			this._slideShowButton.innerHTML = '&nbsp;';
			Sys.UI.DomEvent.addHandler(this._slideShowButton, 'click', this._slideShowButtonClickedDelegate);
		}
		else {
			this._slideShowButton.style.display = 'none';
		}

		if (this._slideShowButtonClickedDelegate != null) {
			this._addCssClass(this._pauseButton, 'pausebutton');
			this._pauseButton.innerHTML = '&nbsp;';
			Sys.UI.DomEvent.addHandler(this._pauseButton, 'click', this._pauseButtonClickedDelegate);
		}
		this._pauseButton.style.display = 'none';

		if (this._loadingStatus != null) {
			if (!Typps.Utility.isNullOrEmpty(this._loadingMessage))
				this._loadingStatus.appendChild(document.createTextNode(this._loadingMessage));
			this._loadingStatus.style.display = 'none';
		}

		this.windowMediaFrame.style.margin = '0';

		if (!this._isDisplayStatic) {
			this.windowMediaFrame.style.position = 'absolute';
			this._contentContainer.style.width = this._minFrameWidth + 'px';
			this._contentContainer.style.height = this._minFrameHeight + 'px';
			Typps.Utility.setLocation(this.windowMediaFrame);
			this._positionFloatingNavigator();
			if (this._largeMediaItem == 0)
				this._contentContainer.style.overflow = 'hidden';
		} else {
			this.windowMediaFrame.style.width = this._minFrameWidth + 'px';
			var div = document.createElement('div');
			div.style.width = this._minFrameWidth + 'px';
			div.style.height = this._minFrameHeight + 'px';
			div.style.overflow = 'hidden';
			div.appendChild(this._contentContainer.parentNode.removeChild(this._contentContainer));
			this._footer.parentNode.insertBefore(div, this._footer);
			this._closeButton.style.display = 'none';
		}
		if (!this._displayHeader)
			this._header.style.display = 'none';

		if (this._preloadAll)
			this._preloadImages();
		this._createPagerButtons();
		this._createBlockScreen();
		this.startByIndex(pageIndex);
	},
	_positionLoadingStatus: function () {
		if (this._loadingStatus == null || !this._displayLoadingStatus) return;
		var h = this.get_events().getHandler('onrepositionloadingstatus');
		if (h) h(this, this._loadingStatus);
	},
	_showStatus: function () {
		if (this._loadingStatus == null || !this._displayLoadingStatus) return;
		this._loadingStatus.style.display = '';
		this._positionLoadingStatus();
		var h = this.get_events().getHandler('onshowloadingstatus');
		if (h) h(this, this._loadingStatus);
	},
	_hideStatus: function () {
		if (this._loadingStatus == null || !this._displayLoadingStatus) return;
		this._loadingStatus.style.display = 'none';
		var h = this.get_events().getHandler('onhideloadingstatus');
		if (h) h(this, this._loadingStatus);
	},
	_createPagerButtons: function () {
		if (this._allowPaging && this._pagerButtons != null) {
			if (this._pagerButtonsList != null) return;
			this._pagerButtonsList = [];
			if (this._pageSize > this._totalPages)
				this._pageSize = 1;
			for (var num2 = 0; num2 < this._totalPages; num2++) {
				var a = document.createElement('a');
				a.title = this._mediaList[num2].title;
				a.innerHTML = num2 + 1;
				a.className = 'pagerbutton';
				if (num2 > this._pageSize - 1)
					a.style.display = 'none';
				Sys.UI.DomEvent.addHandler(a, 'click', this._pagerButtonClickedDelegate);
				Array.add(this._pagerButtonsList, a);
				this._pagerButtons.appendChild(a);
			}
			if (this._totalPages > this._pageSize) {
				Sys.UI.DomEvent.addHandler(this._moreButtonForward, 'click', this._pagerButtonClickedDelegate);
				Sys.UI.DomEvent.addHandler(this._moreButtonBackward, 'click', this._pagerButtonClickedDelegate);
			}
			if (this._pagerButtonsList.length > this._pageSize) {
				this._moreButtonForward.style.display = '';
				this._moreButtonForward.setAttribute('pageindex', this._pageSize);
			}
		}
	},
	navigateMedia: function (direction) {
		this._navigateMedia({ direction: direction, cachedIndex: null });
	},
	_navigateMedia: function (options) {
		var direction = options.direction;
		var cachedIndex = options.cachedIndex;
		if (direction == 0 && this.get_isEOF())
			return; //we reached the end.we got no where to go
		else if (direction == 1 && this.get_isBOF())
			return; //this is the first item. we cannot move beyond that!
		var lastIndex = this._currentMediaIndex;
		var hidePos = (cachedIndex == null) ? lastIndex : cachedIndex;
		var showPos = (direction == 0) ? this.get_nextMediaIndex() : this.get_previousMediaIndex();
		var rightPos = 0;
		var showOptions = this._createAndPreloadImageByIndex(showPos);
		if (!showOptions.ready) {
			this._currentMediaIndex = lastIndex;
			Array.add(this._pendingNavigatorMethods, {
				methodName: '_navigateMedia',
				args: { direction: direction, cachedIndex: cachedIndex, id: showOptions.id }
			});
			return;
		}
		var hideOptions = this._getMediaByIndex(hidePos);
		if (direction == 0) {
			if (this._moreButtonForward.style.display != 'none')
				rightPos = parseInt(this._moreButtonForward.getAttribute('pageindex'));
			if (rightPos == 0)
				rightPos = this._pageSize;
			if (showPos == rightPos && this._allowPaging)
				this._pagerMovingForward(rightPos);
		}
		else if (direction == 1) {
			if (this._moreButtonBackward.style.display != 'none')
				rightPos = parseInt(this._moreButtonBackward.getAttribute('pageindex'));
			if (showPos == rightPos && this._allowPaging)
				this._pagerMovingBackwards(rightPos + this._pageSize);
		}
		this._hideMedia(hideOptions);
		this._showMedia(showOptions);
		this._toggleSelectedPagerButton(showPos);
	},
	_toggleSelectedPagerButton: function (selectedPagerButtonIndex) {
		if (this._pagerButtonsList == null) return;
		for (var num1 = 0; num1 < this._pagerButtonsList.length; num1++) {
			var button = this._pagerButtonsList[num1];
			if (num1 == selectedPagerButtonIndex) {
				if (!Typps.Utility.containsCssClass(button, this._selectedPageClassName))
					this._toggleCssClass(button, this._selectedPageClassName);
			}
			else {
				if (Typps.Utility.containsCssClass(button, this._selectedPageClassName))
					this._toggleCssClass(button, this._selectedPageClassName);
			}
		}
	},
	_targetControlHandler: function (args) {
		var h = this.get_events().getHandler('targetcontrolclick');
		if (h) h(this, args);
		var elem = args.target;
		var value = elem.getAttribute('value');
		var index = this._getMediaIndexByValue(value);
		if (this._mediaItems != null && this._mediaItems.length > 0) {
			if (index == -1)
				index = 0;
			this.mediaFrameInitCallback(index);
		}
		return false;
	},
	_thumbnailClickedHandler: function (args) {
		var elem = args.target;
		var h = this.get_events().getHandler('thumbnailclick');
		if (h) h(args);
		var value = elem.getAttribute('value');
		var index = this._getMediaIndexByValue(value);
		if (this._mediaItems != null && this._mediaItems.length > 0) {
			if (index == -1)
				index = 0;
			this.mediaFrameInitCallback(index);
		}
		return false;
	},
	_pagerMovingForward: function (currentIndex) {
		var length = this._pagerButtonsList.length;
		var pageIndex = currentIndex;
		if (currentIndex == 0)
			currentIndex = this._pageSize;

		var leftPos = Math.abs(currentIndex - this._pageSize);
		var remainingSize = Math.abs(length - currentIndex);

		var counter = this._pageSize;
		if (remainingSize < this._pageSize)
			counter = remainingSize;
		for (var num1 = 0; num1 < counter; num1++) {
			var midPos = leftPos + num1;
			if (midPos >= 0 && midPos <= length) {
				var button = this._pagerButtonsList[midPos];
				button.style.display = 'none';
				midPos = currentIndex + num1;
				button = this._pagerButtonsList[midPos];
				if (button != null)
					button.style.display = '';
				pageIndex = midPos;
			}
		}
		this._moreButtonBackward.style.display = (pageIndex == 0) ? 'none' : '';
		this._moreButtonBackward.setAttribute('pageindex', leftPos);
		this._moreButtonForward.style.display = (length == pageIndex + 1) ? 'none' : '';
		this._moreButtonForward.setAttribute('pageindex', pageIndex + 1);
		return pageIndex;
	},
	_pagerMovingBackwards: function (currentIndex) {
		pageIndex = currentIndex;
		var length = this._pagerButtonsList.length;
		var rightPos = (currentIndex - this._pageSize);
		var leftPos = (rightPos - this._pageSize);
		if (leftPos < 0) {
			leftPos = -1;
			rightPos = this._pageSize - 1;
		}
		for (var num1 = 0; num1 < length; num1++) {
			var button = this._pagerButtonsList[num1];
			if (num1 > leftPos && num1 <= rightPos) {
				button.style.display = '';
				pageIndex = num1 + 1;
			}
			else {
				button.style.display = 'none';
			}
		}
		this._moreButtonBackward.setAttribute('pageindex', leftPos);
		leftPos = (pageIndex - this._pageSize);
		this._moreButtonBackward.style.display = (leftPos == 0) ? 'none' : '';
		this._moreButtonForward.style.display = (length == pageIndex) ? 'none' : '';
		this._moreButtonForward.setAttribute('pageindex', pageIndex);
		return pageIndex;
	},
	_previousButtonClickedHandler: function (args) {
		if (this._isLocked()) return false;
		var h = this.get_events().getHandler('previous');
		if (h) h(this, args);
		if (!this.get_isBOF())
			this.navigateMedia(Typps.MediaFrame.Direction.Backward);
		return false;
	},
	_nextButtonClickedHandler: function (args) {
		if (this._isLocked()) return false;
		var h = this.get_events().getHandler('next');
		if (h) h(this, args);
		if (!this.get_isEOF())
			this.navigateMedia(Typps.MediaFrame.Direction.Forward);
		return false;
	},
	_slideShowButtonClickedHandler: function (args) {
		if (this._isLocked()) return false;
		var h = this.get_events().getHandler('slideshow');
		if (h) h(this, args);
		this.windowMediaFrame.style.visibility = 'hidden';
		this._enableNavigationButtons(false);
		this.beginSlideShow();
	},
	beginSlideShow: function () {
		this._pauseButton.style.display = '';
		this._slideShowButton.style.display = 'none';
		if (!this._paused) {
			this._resetMediaElements(Typps.MediaFrame.ResetMode.Start, true);
			this._slideShow();
		} else {
			this._slideShow();
			this._paused = false;
		}
	},
	continueSlideShow: function () {
		this._slideShow();
	},
	_slideShow: function () {
		var context = this;
		if (this._currentMediaIndex < (this._mediaList.length - 1)) {
			var interval = this._slideShowInterval;
			var paused = this._paused;
			if (this._currentMediaIndex == -1 || paused)
				interval = 0;
			this._slideShowTimeout = window.setTimeout(function () {
				context.navigateMedia(Typps.MediaFrame.Direction.Forward);
			}, interval);
		} else {
			if (!this._enableEffects)
				this._backToFirstSlide();
		}
	},
	_backToFirstSlide: function () {
		var context = this;
		window.setTimeout(function () {
			context._pauseButton.style.display = 'none';
			context._slideShowButton.style.display = '';
			context._reset(Typps.MediaFrame.ResetMode.Start);
			context.navigateMedia(Typps.MediaFrame.Direction.Forward);
			context.stopSlideShow();
		}, this._slideShowInterval);
	},
	_isPreloaded: function (id) {
		if (this._preloadedMediaList == null) return false;
		for (var num1 = 0; num1 < this._preloadedMediaList.length; num1++) {
			var value = this._preloadedMediaList[num1];
			if (value == id)
				return true;
		}
		return false;
	},
	stopSlideShow: function () {
		if (this._slideShowTimeout) {
			window.clearInterval(this._slideShowTimeout);
			this._slideShowTimeout = null;
			if (!this._enableEffects)
				this._enableNavigationButtons(true);
		}
	},
	pauseSlideShow: function () {
		this._clearPendingCallbacks();
		this._paused = true;
		this.stopSlideShow();
		this._pauseButton.style.display = 'none';
		this._slideShowButton.style.display = '';
		this._enableNavigationButtons(true);
	},
	_pauseButtonClickedHandler: function (args) {
		var h = this.get_events().getHandler('pause');
		if (h) h(this, args);
		this.pauseSlideShow();
	},
	_pagerButtonClickedHandler: function (args) {
		if (this._isLocked()) return false;
		var pageIndex = args.target.innerHTML;
		var id = args.target.id;
		var movingForward = id.indexOf('forward') != -1;
		var movingBackward = id.indexOf('backward') != -1;
		var direction = Typps.MediaFrame.Direction.Still;
		if (movingForward)
			direction = Typps.MediaFrame.Direction.Forward;
		else if (movingBackward)
			direction = Typps.MediaFrame.Direction.Backward;
		else
			pageIndex = parseInt(pageIndex) - 1;

		this._showByIndexAndDirection({ pageIndex: pageIndex, direction: direction });
		var h = this.get_events().getHandler('pager');
		if (h) h(this, args);
		return false;
	},
	_showByIndexAndDirection: function (options) {
		var pageIndex = options.pageIndex;
		var direction = options.direction;

		var showOptions = null;
		pageIndex = (pageIndex == null) ? pageIndex = 0 : parseInt(pageIndex);
		if (direction == 2) {
			var hidePos = this._currentMediaIndex;
			showOptions = this._createAndPreloadImageByIndex(pageIndex);
			if (!showOptions.ready) {
				Array.add(this._pendingNavigatorMethods, {
					methodName: '_showByIndexAndDirection',
					args: { pageIndex: pageIndex, direction: direction, id: showOptions.id }
				});
				return;
			}
			this._toggleSelectedPagerButton(pageIndex);
			this._currentMediaIndex = pageIndex;
			var hideOptions = this._getMediaByIndex(hidePos);
			this._hideMedia(hideOptions);
			this._showMedia(showOptions);
			return false;
		}
		else {

			showOptions = this._createAndPreloadImageByIndex(this._currentMediaIndex);
			if (!showOptions.ready) {
				Array.add(this._pendingNavigatorMethods, {
					methodName: '_showByIndexAndDirection',
					args: { pageIndex: pageIndex, direction: directio, id: showOptions.idn }
				});
				return;
			}

			var cButton = this._pagerButtonsList[this._currentMediaIndex];
			if (cButton != null && Typps.Utility.containsCssClass(cButton, this._selectedPageClassName))
				this._toggleCssClass(cButton, this._selectedPageClassName);

			var lastIndex = this._currentMediaIndex;
			if (direction == 0) {
				pageIndex = parseInt(this._moreButtonForward.getAttribute('pageindex'));
				this._currentMediaIndex = (pageIndex - 1);
				this._navigateMedia({ direction: Typps.MediaFrame.Direction.Forward,
					cachedIndex: lastIndex
				});
			}
			else {
				pageIndex = parseInt(this._moreButtonBackward.getAttribute('pageindex'));
				this._currentMediaIndex = (pageIndex + 1);
				this._navigateMedia({ direction: Typps.MediaFrame.Direction.Backward,
					cachedIndex: lastIndex
				});
			}
		}
	},
	_createAndPreloadImageByIndex: function (index) {
		return this._getImage({ index: index, preload: true });
	},
	_getMediaByIndex: function (index) {
		return this._getImage({ index: index, preload: false });
	},
	_getImage: function (options) {
		if (typeof options == 'undefined') return null;
		var img = null;
		var id = null;
		var ready = true;
		var index = options.index;
		/*when we are displaying the first element, there is nothing to hide?*/
		if (index > -1) {
			var preload = options.preload;
			id = this.get_id() + '_img' + index;
			img = $get(id);
			if (img == null && preload) {
				ready = false;
				if (!this._isPreloaded(id))
					this._showStatus();
				this._preloadImageByIndex(index);
			}
			if (!this._isPreloaded(id))
				ready = false;
		}
		return { img: img, ready: ready, id: id };
	},
	_displayMedia: function (options, display) {
		if (typeof options == 'undefined') return;
		var elem = options.img;
		var ready = options.ready;
		if (elem == null || !ready) return;
		if (elem.style.display != 'none' && display) return;
		var h = null;
		var args = null;
		if (display) {
			if (!this._isDisplayStatic) {
				var dragElem = (this._enableEffects) ? this._innerBlock : this._contentContainer;
				dragElem.scrollLeft = 0;
				dragElem.scrollTop = 0;
				var dimentions = this._getElementDimentions(elem);
				if (this._enableEffects)
					elem.style.visibility = 'hidden';

				if (!this._enableEffects) {
					this._contentContainer.style.width = dimentions.width + 'px';
					this._contentContainer.style.height = dimentions.height + 'px';
					Typps.Utility.setLocation(this.windowMediaFrame);
				}
				if (this._largeMediaItem == Typps.MediaFrame.MediaItemOverflow.AllowDrag &&
                        (dimentions.isFat && elem.isDraggable == undefined)) {
					if (this._mouseDownDelegate === null)
						this._mouseDownDelegate = Function.createDelegate(this, this._mouseDownHandler);
					if (this._mouseUpDelegate1 === null)
						this._mouseUpDelegate1 = Function.createDelegate(this, this._mouseUpHandler1);
					Sys.UI.DomEvent.addHandler(elem, 'mousedown', this._mouseDownDelegate);
					Sys.UI.DomEvent.addHandler(elem, 'mouseup', this._mouseUpDelegate1);
					elem.style.cursor = String.format('url({0}),auto', this._grabCursor);
					elem.isDraggable = true;
				}
			}
			args = new Typps.MediaItemEventArgs();
			args.set_sender(this);
			args.set_element(elem);
			args.set_header(this._header);
			args.set_footer(this._footer);
			args.set_oldWidth(this._contentContainer.offsetWidth);
			args.set_oldHeight(this._contentContainer.offsetHeight);

			if (elem.src.indexOf(this._loadFailureMediaUrl) == -1)
				this._caption.innerHTML = elem.title;
			else
				this._caption.innerHTML = this._loadFailureMessage;

			h = this.get_events().getHandler('onmediaitemdisplay');
			if (h) { h(this, args); return; }
			//use changed handler when wanting a mediaitemdisplay but without wanting to exit
			h = this.get_events().getHandler('onmediaitemshow');
			if (h) { h(this, args); }
			this.windowMediaFrame.style.visibility = 'visible';
		} else {
			elem.style.display = 'none';
		}
	},
	_enableNavigationButtons: function (enabledState) {
		if (this._slideShowTimeout != null) return;
		if (typeof enabledState == 'undefined')
			enabledState = true;
		var commandButtonClassName = 'commandbutton-disabled';
		var pagerButtonClassName = 'pagerbutton-disabled';

		this._toggleClassName(this._slideShowButton, commandButtonClassName, enabledState);

		var buttons = [this._firstButton, this._previousButton, this._nextButton, this._lastButton];
		for (var index1 in buttons) {
			var button = buttons[index1];
			this._toggleClassName(button, pagerButtonClassName, enabledState);
		}

		this._toggleClassName(this._moreButtonForward, pagerButtonClassName, enabledState);
		this._toggleClassName(this._moreButtonBackward, pagerButtonClassName, enabledState);

		for (var index2 in this._pagerButtonsList) {
			var pagerButton = this._pagerButtonsList[index2];
			this._toggleClassName(pagerButton, pagerButtonClassName, enabledState);
		}
	},
	_toggleClassName: function (elem, className, enabledState) {
		if (!enabledState) {
			this._addCssClass(elem, className);
			elem.style.cursor = 'default';
		}
		else {
			this._removeCssClass(elem, className);
			elem.style.cursor = 'pointer';
		}
	},
	showMedia: function (elem) {
		this._displayMedia({ img: elem, ready: true, display: true });
	},
	hideMedia: function (elem) {
		this._displayMedia({ img: elem, ready: true, display: false });
	},
	_showMedia: function (options) {
		this._displayMedia(options, true);
		if (options.ready) {
			if (this._enableEffects) {
				this._enableNavigationButtons(false);
				this._addShowEffect(options.img);
			}
			else {
				this._enableNavigationButtons(true);
				options.img.style.display = '';
				if (this._slideShowTimeout != null && (this._currentMediaIndex < (this._mediaList.length - 1)))
					this._slideShow();
				else if (this._slideShowTimeout != null)/*it's a slide show but we already got to the last item*/
					this._backToFirstSlide();
			}
		}
	},
	_hideMedia: function (options) {
		if (options.img != null) {
			if (this._enableEffects)
				this._addHideEffect(options.img);
			else
				this._displayMedia(options, false);
		}
	},
	_addShowEffect: function (elem) {
		var effectMove = null;
		/*effects don't work too well in ie8, in fact they appear to run a tad slower than normal,
		so if effects are important then most likely setting docment compatibility mode to ie7 is the best solution eg:
		<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
		. we'll try and fix this in subsequent releases*/
		if (!this._isDisplayStatic) {
			effectMove = this._getMoveEffect(elem);
			this._registerObservers(effectMove, { elem: elem, action: Typps.MediaFrame.Action.None });
		}
		var effectSlideOrFade = null;
		if (this._effectsCluster == null)
			effectSlideOrFade = new Spry.Effect.Fade(this._contentContainer.id, { from: '0%', to: '100%' });
		else
			effectSlideOrFade = new Spry.Effect.Slide(this._contentContainer.id, { from: '0%', to: '100%', duration: 500, horizontal: this._slideEffectHorizontal });

		var effectSize = null;
		if (!this._isDisplayStatic)
			effectSize = this._getSizeEffect(elem);

		this._ensureEffectsCluster();
		if (effectMove != null)
			this._effectsCluster.addNextEffect(effectMove);
		this._effectsCluster.addNextEffect(effectSlideOrFade);
		if (effectSize != null)
			this._effectsCluster.addNextEffect(effectSize);
		if (this._displayHeader) {
			var effectFade = new Spry.Effect.Fade(this._header.id, { from: '0%', to: '100%' });
			this._effectsCluster.addNextEffect(effectFade);
			this._registerObservers(effectFade, { elem: elem, action: Typps.MediaFrame.Action.None });
		}
		if (effectSize != null)
			this._registerObservers(effectSize, { elem: elem, action: Typps.MediaFrame.Action.Resize });

		this._registerObservers(effectSlideOrFade, { elem: elem, action: Typps.MediaFrame.Action.Show });
		this._registerClusterObserver(this._effectsCluster);
		this._effectsCluster.start();
	},
	_addHideEffect: function (elem) {
		this._ensureEffectsCluster();
		if (this._displayHeader) {
			var effectFade = new Spry.Effect.Fade(this._header.id, { from: '100%', to: '0%' });
			this._effectsCluster.addNextEffect(effectFade);
			this._registerObservers(effectFade, { elem: elem, action: Typps.MediaFrame.Action.None });
		}
		var effectSlide = new Spry.Effect.Slide(this._contentContainer.id, { from: '100%', to: '0%', duration: 500,
			horizontal: this._slideEffectHorizontal, transition: Spry.growSpecificTransition
		});
		this._effectsCluster.addNextEffect(effectSlide);
		this._registerObservers(effectSlide, { elem: elem, action: Typps.MediaFrame.Action.Hide });
		this._registerClusterObserver(this._effectsCluster);
	},
	_ensureEffectsCluster: function () {
		if (this._effectsCluster == null)
			this._effectsCluster = new Spry.Effect.Cluster({ toggle: false });
	},
	_registerObservers: function (effect, args) {
		var context = this;
		var observe = Function.createCallback(context._onObserverHandler, { context: context, elem: args.elem, action: args.action });
		effect.addObserver(observe);
	},
	_onObserverHandler: function (notificationType, eff, data, args) {
		var context = args.context;
		switch (notificationType) {
			case 'onPreEffect':
				if (args.action == Typps.MediaFrame.Action.Resize) {
					var width = eff.stopWidth + 'px';
					var height = eff.stopHeight + 'px';
					context.windowMediaFrame.style.width = width;
					context.windowMediaFrame.style.height = height;
					context._innerBlock.style.width = width;
					context._innerBlock.style.height = height;
				}
				else if (args.action == Typps.MediaFrame.Action.Show) {
					args.elem.style.display = '';
				}
				break;
			case 'onPostEffect':
				if (eff.name == 'Size')
					args.elem.style.visibility = 'visible';
				if (args.action == Typps.MediaFrame.Action.Hide)
					args.elem.style.display = 'none';
				break;
		}
	},
	_registerClusterObserver: function (effectsCluster) {
		var context = this;
		if (this._onClusterObserveDelegate == null)
			this._onClusterObserveDelegate = Function.createCallback(context._onClusterObserverHandler, { context: context });
		effectsCluster.addObserver(this._onClusterObserveDelegate);
	},
	_onClusterObserverHandler: function (notificationType, eff, data, args) {
		var context = args.context;
		switch (notificationType) {
			case 'onPostEffect':
				context._disposeClusterEffect();
				context._enableNavigationButtons(true);
				/*is this a slideshow and are we within range*/
				if (context._slideShowTimeout != null && (context._currentMediaIndex < (context._mediaList.length - 1)))
					context._slideShow();
				else if (context._slideShowTimeout != null)/*it's a slide show but we already got to the last item*/
					context._backToFirstSlide();
				break;
			case 'onCancel':
				context._disposeClusterEffect();
				context._restoreDefaultStyles();
				context._enableNavigationButtons(true);
				break;
		}
	},
	_disposeClusterEffect: function () {
		if (this._effectsCluster == null) return;
		var effectsArray = this._effectsCluster.effectsArray;
		var length = effectsArray.length - 1;
		for (var num1 = length; num1 >= 0; num1--) {
			var item = effectsArray[num1];
			if (item != null)
				Array.remove(effectsArray, item);
		}
		if (this._onClusterObserveDelegate != null)
			this._effectsCluster.removeObserver(this._onClusterObserveDelegate);
		delete this._effectsCluster;
		this._effectsCluster = null;
	},
	_restoreDefaultStyles: function () {
		/*special effects normally change the original elements appearance and we want the default state back
		in case an effect got cancelled in the middle*/
		this.windowMediaFrame.removeAttribute('style');
		this._contentContainer.removeAttribute('style');
		this._innerBlock.removeAttribute('style');
		if (this._displayHeader)
			this._header.removeAttribute('style');

		if (!this._isDisplayStatic) {
			this.windowMediaFrame.style.position = 'absolute';
			Typps.Utility.setLocation(this.windowMediaFrame);
			this.windowMediaFrame.style.width = 'auto';
			if (this._floatingNav != null) {
				var zIndex = parseInt(this._floatingNav.style.zIndex);
				this.windowMediaFrame.style.zIndex = zIndex - 1;
			}
			this._contentContainer.style.width = this._minFrameWidth + 'px';
			this._contentContainer.style.height = this._minFrameHeight + 'px';
			if (this._largeMediaItem == 0)
				this._contentContainer.style.overflow = 'hidden';
		}
		else {
			this.windowMediaFrame.style.width = this._minFrameWidth + 'px';
		}

		var images = this._innerBlock.getElementsByTagName('img');
		for (var num1 = 0; num1 < images.length; num1++) {
			var img = images[num1];
			img.style.display = 'none';
		}
	},
	_getMoveEffect: function (elem) {
		var display = elem.style.display;
		if (display == 'none')
			elem.style.display = '';

		var newSize = this._getElementDimentions(elem);

		var location = Typps.Utility.getLocationByElement(elem);
		if (newSize.isFat) {
			newSize.height += this._getOuterSpace();
			location = Typps.Utility.getLocationBySize(newSize.width, newSize.height);
		}
		var fromPos = new Spry.Effect.Utils.Position();
		fromPos.x = this.windowMediaFrame.offsetLeft;
		fromPos.y = this.windowMediaFrame.offsetTop;

		var toPos = new Spry.Effect.Utils.Position();
		toPos.x = location.x;
		toPos.y = location.y;
		elem.style.display = display;

		return new Spry.Effect.Move(this.windowMediaFrame.id, fromPos, toPos, { duration: 500, fps: 20 });
	},
	_getSizeEffect: function (elem) {
		var newSize = this._getElementDimentions(elem);
		var fromRect = new Spry.Effect.Utils.Rectangle;
		fromRect.width = this._contentContainer.offsetWidth;
		fromRect.height = this._contentContainer.offsetHeight;

		var toRect = new Spry.Effect.Utils.Rectangle;
		toRect.width = newSize.width;
		toRect.height = newSize.height;

		Spry.Effect.makeClipping(this._contentContainer);
		return new Spry.Effect.Size(this._contentContainer.id, fromRect, toRect, { duration: 500, scaleContent: false, fps: 20 });
	},
	_getElementDimentions: function (elem) {
		var display = elem.style.display;
		if (display == 'none')
			elem.style.display = '';
		var barWidth = 0;
		var bounds = Typps.Utility.windowBounds();
		var outerHeight = this._getOuterSpace();
		var html = document.getElementsByTagName('html')[0];
		var width = elem.offsetWidth;
		var height = elem.offsetHeight;

		var flag1 = false;

		if (((width + barWidth) < this._minFrameWidth) && this._isDisplayStatic) {
			width = this._minFrameWidth;
		} else if ((width + barWidth) >= bounds.ix) {
			width = bounds.ix - (20 + barWidth);
			flag1 = true;
		}
		if ((height < this._minFrameHeight) && this._isDisplayStatic) {
			height = this._minFrameHeight;
		}
		else if ((height + outerHeight) >= bounds.iy) {
			height = bounds.iy - (10 + outerHeight);
			flag1 = true;
		}
		elem.style.display = display;
		return { height: height, width: width, isFat: flag1 };
	},
	_getOuterSpace: function () {
		var height = 0;
		if (this._floatingNav != null && (this._floatingNav.style.visibility != 'hidden' &&
            this._floatingNav.style.display != 'none')) {
			var navStyle = Sys.UI.DomElement._getCurrentStyle(this._floatingNav);
			height += this._getPaddingFromStyle(navStyle);
			height += this._getMarginFromStyle(navStyle);
			height += this._getHeightFromStyle(navStyle);
		}
		else if (this._floatingNav == null) {
			var footerStyle = Sys.UI.DomElement._getCurrentStyle(this._footer);
			height += this._getPaddingFromStyle(footerStyle);
			height += this._getMarginFromStyle(footerStyle);
			height += this._getHeightFromStyle(footerStyle);
		}
		if (this._displayHeader) {
			var headerStyle = Sys.UI.DomElement._getCurrentStyle(this._header);
			height += this._getPaddingFromStyle(headerStyle);
			height += this._getMarginFromStyle(headerStyle);
			height += this._getHeightFromStyle(headerStyle);
		}
		return height;
	},
	_getPaddingFromStyle: function (style) {
		var padding = 0;
		var paddingTop = parseInt(style.paddingTop);
		var paddingBottom = parseInt(style.paddingBottom);
		if (!isNaN(paddingTop))
			padding += paddingTop;
		if (!isNaN(paddingBottom))
			padding += paddingBottom;
		return padding;
	},
	_getMarginFromStyle: function (style) {
		var margin = 0;
		var marginTop = parseInt(style.marginTop);
		var marginBottom = parseInt(style.marginBottom);
		if (!isNaN(marginTop))
			margin += marginTop;
		if (!isNaN(marginBottom))
			margin += marginBottom;
		return margin;
	},
	_getHeightFromStyle: function (style) {
		var height = 0;
		var borderWidth = parseInt(style.borderTopWidth);
		var innerHeight = parseInt(style.height);
		if (!isNaN(borderWidth))
			height += borderWidth;
		if (!isNaN(innerHeight))
			height += innerHeight;
		return height;
	},
	_isLocked: function () {
		if (this._slideShowTimeout != null || this._isEffectOrLoadingStatusRunning())
			return true;
		return false;
	},
	_isEffectOrLoadingStatusRunning: function () {
		var display = this._loadingStatus.style.display;
		if (display == '') return true;
		return this._isEffectsClusterRunning();
	},
	_isEffectsClusterRunning: function () {
		if (this._effectsCluster != null && this._effectsCluster.isRunning)
			return true;
		return false;
	},
	_cancelClusterEffect: function () {
		if (this._isEffectsClusterRunning())
			this._effectsCluster.cancel();
	},
	_mouseUpHandler1: function (args) {
		var elem = args.target;
		elem.style.cursor = String.format('url({0}),auto', this._grabCursor);
	},
	_mouseDownHandler: function (args) {
		var elem = args.target;
		elem.style.cursor = String.format('url({0}),auto', this._grabbingCursor);
		args.preventDefault();
		if (this._enableEffects)
			this._innerBlock.style.overflow = 'hidden';

		if (this._slideShowTimeout != null)
			this.pauseSlideShow();
		this._release(args);
		this._startMouseX = args.clientX;
		this._startMouseY = args.clientY;
		this._startX = elem.offsetLeft;
		this._startY = elem.offsetTop;
		if (this._mouseMoveDelegate === null)
			this._mouseMoveDelegate = Function.createDelegate(this, this._mouseMoveHandler);
		Sys.UI.DomEvent.addHandler(document, 'mousemove', this._mouseMoveDelegate);
		if (this._mouseUpDelegate2 === null)
			this._mouseUpDelegate2 = Function.createDelegate(this, this._mouseUpHandler2);
		Sys.UI.DomEvent.addHandler(document, 'mouseup', this._mouseUpDelegate2);
		return false;
	},
	_mouseMoveHandler: function (args) {
		var elem = this._mediaList[this._currentMediaIndex];
		var x = (args.clientX - this._startMouseX) + this._startX;
		var y = (args.clientY - this._startMouseY) + this._startY;
		var dragElem = (this._enableEffects) ? this._innerBlock : this._contentContainer;
		if (args.clientX != this._clientX) {
			var speedx = (this._dragSpeed == 0) ? Math.abs(x) : this._dragSpeed;
			if (x > 0)
				dragElem.scrollLeft -= speedx;
			else
				dragElem.scrollLeft += speedx;
		}
		if (args.clientY != this._clientY) {
			var speedy = (this._dragSpeed == 0) ? Math.abs(y) : this._dragSpeed;
			if (y > 0)
				dragElem.scrollTop -= speedy;
			else
				dragElem.scrollTop += speedy;
		}
		this._clientX = args.clientX;
		this._clientY = args.clientY;
		return false;
	},
	_mouseUpHandler2: function (args) {
		var elem = args.target;
		elem.style.cursor = String.format('url({0}),auto', this._grabCursor);
		this._release(args);
		return false;
	},
	_mediaElementClickedHandler: function (args) {
		var h = this.get_events().getHandler('mediaelementclicked');
		if (h) h(this, args);
	},
	_release: function (args) {
		this._clientX = null;
		this._clientY = null;
		if (this._mouseMoveDelegate != null) {
			Sys.UI.DomEvent.removeHandler(document, 'mousemove', this._mouseMoveDelegate);
			delete this._mouseMoveDelegate;
			this._mouseMoveDelegate = null;
		}
		if (this._mouseUpDelegate2 != null) {
			Sys.UI.DomEvent.removeHandler(document, 'mouseup', this._mouseUpDelegate2);
			delete this._mouseUpDelegate2;
			this._mouseUpDelegate2 = null;
		}
	},
	start: function () {
		this._show(true, null);
	},
	startByIndex: function (index) {
		this._show(true, index);
	},
	stop: function () {
		this._show(false, null);
	},
	_show: function (display, pageIndex) {
		this._toggleSelectElement();
		var zIndex = Typps.Utility.incrementZIndex(3);
		if (display) {
			if (this._floatingNav != null) {
				this._floatingNav.style.display = '';
				this._floatingNav.style.zIndex = zIndex;
				--zIndex;
			}
			this.windowMediaFrame.style.zIndex = zIndex;
			this.windowMediaFrame.style.display = '';
			if (!this._autoStartSlideShow) {
				if (pageIndex == null) {
					this.navigateMedia(Typps.MediaFrame.Direction.Forward);
				} else {
					this._showByIndexAndDirection({ pageIndex: pageIndex, direction: Typps.MediaFrame.Direction.Still });
					this.reOrganizePager(pageIndex);
				}
			} else {
				this.beginSlideShow();
			}
		} else {
			if (!this._isDisplayStatic)
				this.windowMediaFrame.style.display = 'none';
			this._reset(Typps.MediaFrame.ResetMode.Start);

			this._paused = false;
			this.stopSlideShow();
			this._pauseButton.style.display = 'none';
			if (this._allowSlideShow)
				this._slideShowButton.style.display = '';
		}
		this._toggleBlockScreen();
		if (display)
			this._applyBlockScreenBounds();
	},
	_getMediaIndexByValue: function (match) {
		if (match == null || match == undefined) return -1;
		for (var num1 = 0; num1 < this._mediaList.length; num1++) {
			var img = this._mediaList[num1];
			var toMatch = img.getAttribute('value');
			if (toMatch != undefined && toMatch == match)
				return num1;
		}
		return -1;
	},
	_preloadImageByIndex: function (index) {
		var context = this;
		var onload = Function.createCallback(context._preloadHandler, context);
		var onerror = Function.createCallback(context._preloadOnErrorHandler, context);
		var item = this._mediaItems[index];
		this._imageLoader.load(item.url, onload, item.priority, onerror, index);
	},
	_preloadImages: function () {
		var context = this;
		var onload = Function.createCallback(context._preloadHandler, context);
		var onerror = Function.createCallback(context._preloadOnErrorHandler, context);
		for (var index in this._mediaItems) {
			var item = this._mediaItems[index];
			if (item.preload)
				this._imageLoader.load(item.url, onload, item.priority, onerror, index);
		}
	},
	_existsInPreloadList: function (id) {
		for (var index in this._pendingPreloadList) {
			var item = this._pendingPreloadList[index];
			if (item.id == id)
				return true;
		}
		return false;
	},
	_preloadHandler: function (url, index, loader, context) {
		var h = context.get_events().getHandler('mediapreload');
		if (h) h(context, args);
		var id = context.get_id() + '_img' + index;
		var target = context._mediaList[index];
		context._innerBlock.appendChild(target);
		target.src = url;

		/*actual target is loader, but we don't really need it*/
		var args = { target: target, preloading: true, preloadedImageId: id };
		//context._mediaElementLoadedHandler(args);
	},
	_preloadOnErrorHandler: function (url, index, loader, context) {
		var h = context.get_events().getHandler('mediapreloadonerror');
		if (h) h(context, args);
		var id = context.get_id() + '_img' + index;
		var target = context._mediaList[index];
		context._innerBlock.appendChild(target);
		/*actual target is loader, but we don't really need it*/
		var args = { target: target, preloading: true, preloadedImageId: id };
		if (context._isIE)
			args = { srcElement: target, preloading: true, preloadedImageId: id };
		//mm is this the only way?
		//looks clunky! why did i do this?
		context._mediaElementOnErrorHandler(context, args);
	},
	_mediaElementLoadedHandler: function (args) {
		if (args == null) return;
		var elem = args.target;
		/*not very interesting but perhaps we should just let caller pass an identifier
		saying this is a preloaded image and raise the mediaelementloaded handler anyway?*/
		if (!args.preloading) {
			var h = this.get_events().getHandler('mediaelementloaded');
			if (h) h(args);
		}
		if (!args.preloading)
			this._hideStatus();
		var id = args.preloadedImageId;
		if (elem != null)
			id = elem.id;
		if (!this._isPreloaded(id))
			Array.add(this._preloadedMediaList, id);
		if (args.preloading) return;
		this._processQue(elem);
	},
	_processQue: function (elem) {
		var hasCallback = this._hasCallbackMethod(elem.id);
		if (hasCallback)
			this._executeOrClearPendingCallbacks(true);
	},
	_mediaElementOnErrorHandler: function (args1, args2) {
		/*ie does not pass the event, so lets workaround! */
		var context = null;
		var args = null;
		if (args2 == null) {
			args = window.event;
			context = args1;
		}
		else {
			args = args1;
			context = args2;
		}
		var elem = (context._isIE) ? args.srcElement : args.target;
		if (context._loadFailureMediaUrl != null && elem.src.indexOf(context._loadFailureMediaUrl) == -1) {
			context._hideStatus();
			elem.style.display = 'none';
			elem.src = context._loadFailureMediaUrl;
		}
		if (!args.preloading) {
			var h = context.get_events().getHandler('mediaelementonloaderror');
			if (h) h(context, args);
		}
		var id = args.preloadedImageId;
		if (elem != null)
			id = elem.id;
		if (!context._isPreloaded(id))
			Array.add(context._preloadedMediaList, id);
		if (args.preloading) return;
		context._processQue(elem);
	},
	_executeOrClearPendingCallbacks: function (runMethods) {
		var length = this._pendingNavigatorMethods.length - 1;
		for (var num1 = length; num1 >= 0; num1--) {
			var item = this._pendingNavigatorMethods[num1];
			if (runMethods)
				this[item.methodName](item.args);
			Array.remove(this._pendingNavigatorMethods, item);
		}
	},
	_clearPendingCallbacks: function () {
		this._executeOrClearPendingCallbacks(false);
	},
	_hasCallbackMethod: function (id) {
		for (var num1 = 0; num1 < this._pendingNavigatorMethods.length; num1++) {
			var item = this._pendingNavigatorMethods[num1];
			if (id == id) return true;
		}
		return false;
	},
	reset: function (resetMode) {
		if (resetMode == null)
			this._reset(Typps.MediaFrame.ResetMode.Start);
		else
			this._reset(resetMode);
	},
	_reset: function (resetMode) {
		this._resetMediaElements(resetMode, true);
	},
	_resetMediaElements: function (resetMode, resetCurrentMediaItem) {
		if (this._currentMediaIndex == -1 || this._pagerButtonsList == null) return;
		var length = this._pagerButtonsList.length;
		if (resetCurrentMediaItem) {
			var b = this._pagerButtonsList[this._currentMediaIndex];
			if (b != null && Typps.Utility.containsCssClass(b, this._selectedPageClassName))
				this._toggleCssClass(b, this._selectedPageClassName);
			this._mediaList[this._currentMediaIndex].style.display = 'none';
		}
		if (resetMode == 0)
			this._currentMediaIndex = -1;
		else
			this._currentMediaIndex = length;
		var pageIndex = 0;
		if (resetMode == 1)
			pageIndex = length - 1;
		this.reOrganizePager(pageIndex);
	},
	_firstButtonClickedHandler: function (args) {
		if (this._isLocked()) return;
		var h = this.get_events().getHandler('first');
		if (h) h(this, args);
		if (!this.get_isBOF()) {
			var currentIndex = this._currentMediaIndex;
			this._resetMediaElements(Typps.MediaFrame.ResetMode.Start, false);
			this._navigateMedia({ direction: Typps.MediaFrame.Direction.Forward, cachedIndex: currentIndex });
		}
	},
	_lastButtonClickedHandler: function (args) {
		if (this._isLocked()) return;
		var h = this.get_events().getHandler('last');
		if (h) h(this, args);
		if (!this.get_isEOF()) {
			var currentIndex = this._currentMediaIndex;
			this._resetMediaElements(Typps.MediaFrame.ResetMode.End, false);
			this._navigateMedia({ direction: Typps.MediaFrame.Direction.Backward, cachedIndex: currentIndex });
		}
	},
	_closeButtonClickedHandler: function (args) {
		var index = this._currentMediaIndex;
		if (index == -1)
			index = 0;
		var item = this._mediaItems[index];
		var argument = new Typps.EventArgs();
		argument.set_commandName(item.value);
		argument.set_commandArgument(item.url);
		argument.set_innerArgs(args);
		var h = this.get_events().getHandler('close');
		if (h) h(this, argument);
		if (this._enableEffects && this._displayHeader)
			this._header.style.visibility = 'hidden';
		if (this._floatingNav != null)
			this._floatingNav.style.display = 'none';
		this._clearPendingCallbacks(); //just in case
		this._restoreDefaultStyles(); //restore the defaults
		this._cancelClusterEffect();
		this.stop();
		this._enableNavigationButtons(true);
		return false;
	},
	_abortRequestHandler: function (args) { },
	mediaFrameInitCallback: function (pageIndex) {
		if (this.windowMediaFrame == null) {
			var argument = Typps.Utility.getCommandArgument('mediaframe', this.get_callbacks());
			var formKeyValuePair = { formdata: argument.commandArgument };
			this._fireUpdatePanelTrigger(formKeyValuePair, argument.commandArgument, argument.message, pageIndex);
		} else {
			this.startByIndex(pageIndex);
		}
	},
	reOrganizePager: function (currentPageIndex) {
		if (this._pagerButtonsList == null) return;
		var length = this._pagerButtonsList.length;
		var pagedIndex = (currentPageIndex + this._pageSize);
		if (pagedIndex > length) {
			pagedIndex = length;
			currentPageIndex = Math.abs(length - this._pageSize);
		}
		for (var num1 = 0; num1 < length; num1++) {
			var button = this._pagerButtonsList[num1];
			if (num1 >= currentPageIndex && num1 < pagedIndex)
				button.style.display = '';
			else
				button.style.display = 'none';
		}
		this._moreButtonBackward.style.display = (currentPageIndex == 0) ? 'none' : '';
		this._moreButtonBackward.setAttribute('pageindex', (pagedIndex - 1));
		this._moreButtonForward.style.display = (length == pagedIndex) ? 'none' : '';
		this._moreButtonForward.setAttribute('pageindex', pagedIndex);
	},
	_onResizeHandler: function (event) {
		Typps.Utility.setLocation(this.windowMediaFrame);
		this._applyBlockScreenBounds();
		this._repositionFloatingNavigator();
	},
	_onScrollHandler: function (event) {
		Typps.Utility.setLocation(this.windowMediaFrame);
		this._applyBlockScreenBounds();
		if (!this._isDisplayStatict && (this._isIE && Sys.Browser.version == 6))
			this._repositionFloatingNavigator();
	},
	_repositionFloatingNavigator: function () {
		if (this._floatingNav == null) return;
		var context = this;
		window.setTimeout(function () {
			context._positionFloatingNavigator();
		}, 0);
	},
	_createBlockScreen: function () {
		var id = this.get_id() + '_dialogframe';
		var shadeElement = Typps.Utility.createBlockScreen(id, this._shaderColor, this._shaderOpacity);
	},
	_toggleBlockScreen: function () {
		if (this._isDisplayStatic) return;

		var zIndex = isNaN(parseInt(this.windowMediaFrame.style.zIndex)) ? 0 : parseInt(this.windowMediaFrame.style.zIndex) - 1;
		var shadeElement = $get(this.get_id() + '_dialogframe');
		Typps.Utility.toggleBlockScreen(shadeElement, zIndex);
	},
	_applyBlockScreenBounds: function () {
		if (this._isDisplayStatic) return;
		var id = this.get_id() + '_dialogframe';
		Typps.Utility.applyBlockScreenBounds(id);
	},
	_ensureFloatingNavigator: function () {
		var div = this._floatingNav;
		if (div == null) {
			div = document.createElement('div');
			div.id = this.get_id() + '_navigator';

			div.style.height = this._floatingNavigatorHeight;

			this._footer = this._footer.parentNode.removeChild(this._footer);
			div.appendChild(this._footer);

			this._addCssClass(div, this._className + ' floatingnavigator');
			Typps.Utility.setFloat(div, 'left');

			if (this._isIE && Sys.Browser.version == 6)
				div.style.position = 'absolute';
			else
				div.style.position = 'fixed';

			document.body.appendChild(div);
			this._floatingNav = div;
		}
		return div;
	},
	_positionFloatingNavigator: function () {
		var elem = this._ensureFloatingNavigator();
		if (elem != null) {
			var bounds = Typps.Utility.windowBounds();
			var barWidth = Typps.Utility.getScrollBarWidth();
			var x = bounds.ix;
			var html = document.getElementsByTagName('html')[0];
			if (html.scrollHeight > bounds.iy && !this._isIE)
				x -= barWidth;
			elem.style.width = x + 'px';
			var top = bounds.iy - elem.offsetHeight;

			var position = Typps.Utility.scrollDistance();
			elem.style.left = position.x + 'px';
			if (this._isIE && Sys.Browser.version == 6)
				elem.style.top = (top + position.y) + 'px';
			else
				elem.style.top = top + 'px';
		}
	},
	_toggleSelectElement: function () {
		this._selects = Typps.Utility.toggleSelectElement(this.windowMediaFrame, this._selects);
	},
	_beginRequestHandler: function (sender, args) {
		var h = this.get_events().getHandler('beginWebRequest');
		if (h) h(this, args);
	},
	_endRequestHandler: function (sender, args, context) {
		var h;
		if (!sender.get_responseAvailable()) {
			h = context.sender.get_events().getHandler('endWebRequest');
			if (h) h(context.sender, args);
			return;
		}
		var eventArgs = new Typps.EventArgs();
		var parts = sender.get_responseData().split(String.format('$callbackdata${0}$sep$', context.sender.get_id()));
		var key = parts[0];
		var value = parts[1];
		eventArgs.set_commandName(key);
		eventArgs.set_commandArgument(value);
		eventArgs.set_innerArgs(args);
		h = context.sender.get_events().getHandler('endWebRequest');
		if (h) h(context.sender, eventArgs);
		switch (key) {
			case 'MediaFrameRequest':
				context.sender._createMediaFrame(value, context.data);
				break;
		}
	},
	_makeWebRequest: function (eventArgs, formKeyValuePair, contextData) {
		var pageManager = Sys.WebForms.PageRequestManager.getInstance();
		var formBody = Typps.Utility.getFormKeyValuePair(this._uniqueId, formKeyValuePair, this._form, this._postbackAllFormData);
		var request = new Sys.Net.WebRequest();
		request.set_url(this._form.action);
		request.get_headers()['X-MicrosoftAjax'] = 'Delta=true';
		request.get_headers()['Cache-Control'] = 'no-cache';
		request.set_timeout(pageManager._asyncPostBackTimeout);
		request.set_body(formBody);
		if (this._updatePanelProgress === null && this._updatePanelProgressId != null)
			this._updatePanelProgress = $find(this._updatePanelProgressId);
		if (this._updatePanelProgress === null) return;

		this._updatePanelProgress.set_loadingMessage(eventArgs.get_commandArgument());
		if (this._beginRequestHandlerDelegate == null) {
			this._beginRequestHandlerDelegate = Function.createDelegate(this, this._beginRequestHandler);
			this._updatePanelProgress.add_beginRequest(this._beginRequestHandlerDelegate);
		}
		if (this._endRequestHandlerDelegate !== null) {
			this._updatePanelProgress.remove_endRequest(this._endRequestHandlerDelegate);
			this._endRequestHandlerDelegate = null;
		}
		this._endRequestHandlerDelegate = Function.createCallback(this._endRequestHandler, { sender: this, data: contextData });
		this._updatePanelProgress.add_endRequest(this._endRequestHandlerDelegate);
		this._updatePanelProgress._makeWebRequest(request);
	},
	_fireUpdatePanelTrigger: function (formKeyValuePair, commandName, message, contextData) {
		var eventArgs = new Typps.EventArgs();
		eventArgs.set_commandName(commandName);
		eventArgs.set_commandArgument(message);
		this._makeWebRequest(eventArgs, formKeyValuePair, contextData);
	},
	_toggleCssClass: function (elem, className) {
		Typps.Utility.addRemoveClassName(elem, className, Typps.Perform.Toggle);
	},
	_addCssClass: function (elem, className) {
		Typps.Utility.addRemoveClassName(elem, className, Typps.Perform.Add);
	},
	_removeCssClass: function (elem, className) {
		Typps.Utility.addRemoveClassName(elem, className, Typps.Perform.Remove);
	}
}
Typps.MediaFrame.registerClass('Typps.MediaFrame',Sys.UI.Control);
Typps.MediaFrame.MediaType=function () { };
Typps.MediaFrame.MediaType.prototype=
{
    Images: 0,
    Multimedia: 1
}
Typps.MediaFrame.MediaType.registerEnum('Typps.MediaFrame.MediaType');
Typps.MediaFrame.Direction=function () { };
Typps.MediaFrame.Direction.prototype=
{
    Forward: 0,
    Backward: 1,
    Still: 2
}
Typps.MediaFrame.Direction.registerEnum('Typps.MediaFrame.Direction');
Typps.MediaFrame.ResetMode=function () { };
Typps.MediaFrame.ResetMode.prototype=
{
    Start: 0,
    End: 1
}
Typps.MediaFrame.ResetMode.registerEnum('Typps.MediaFrame.ResetMode');
Typps.MediaFrame.Position=function () { };
Typps.MediaFrame.Position.prototype=
{
    ModalPopup: 0,
    Static: 1
}
Typps.MediaFrame.Position.registerEnum('Typps.MediaFrame.Position');
Typps.MediaFrame.Action=function () { };
Typps.MediaFrame.Action.prototype=
{
    None: 0,
    Show: 1,
    Hide: 2,
    Resize: 4
}
Typps.MediaFrame.Action.registerEnum('Typps.MediaFrame.Action');
Typps.MediaFrame.MediaItemOverflow=function () { };
Typps.MediaFrame.MediaItemOverflow.prototype=
{
    AllowDrag: 0,
    SqueezeToFit: 1
}
Typps.MediaFrame.MediaItemOverflow.registerEnum('Typps.MediaFrame.MediaItemOverflow');

//Adobe has written an awesome and compact ImageLoader, so let's use that instead of reinventing the wheel.
//----------------------------------------------------------------------------------------------
// Code that follows is extracted from SpryImageLoader.js - version 0.2 - Spry Pre-Release 1.6.1
//
// Copyright (c) 2007. Adobe Systems Incorporated.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//   * Redistributions of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//   * Redistributions in binary form must reproduce the above copyright notice,
//     this list of conditions and the following disclaimer in the documentation
//     and/or other materials provided with the distribution.
//   * Neither the name of Adobe Systems Incorporated nor the names of its
//     contributors may be used to endorse or promote products derived from this
//     software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

var Spry;if(!Spry) Spry={};if(!Spry.Utils) Spry.Utils={};

Spry.Utils.ImageLoader=function () {
    this.queue=[];
    this.timerID=0;
    this.currentEntry=null;
};

Spry.Utils.ImageLoader.prototype.start=function () {
    if(!this.timerID) {
        var self=this;
        this.timerID=setTimeout(function () {
            self.timerID=0;
            self.processQueue();
        },0);
    }
};

Spry.Utils.ImageLoader.prototype.stop=function () {
    if(this.currentEntry) {
        var entry=this.currentEntry;
        entry.loader.onload=null;
        entry.loader.src="";
        entry.loader=null;
        this.currentEntry=null;
        this.queue.unshift(entry);
    }

    if(this.timerID)
        clearTimeout(this.timerID);

    this.timerID=0;
};

Spry.Utils.ImageLoader.prototype.clearQueue=function () {
    this.stop();
    this.queue.length=0;
};

Spry.Utils.ImageLoader.prototype.load=function (url,callback,priority,onErrorCalback,index) {
    if(url) {
        if(typeof priority=="undefined")
            priority=0;
        this.queue.push({ url: url,callback: callback,priority: priority,onErrorCalback: onErrorCalback,index: index });

        // Entries in the queue are sorted by priority. Those entries
        // with a higher priority are at the start of the queue, while
        // those with lower priority are pushed towards the end. If an
        // entry has the same priority as something already in the queue,
        // it gets processed in the order they were received.

        this.queue.sort(function (a,b) { return (a.priority>b.priority)?-1:((a.priority<b.priority)?1:0); });
        this.start();
    }
};

Spry.Utils.ImageLoader.prototype.processQueue=function () {
    if(this.queue.length<1)
        return;

    var entry=this.currentEntry=this.queue.shift();
    var loader=entry.loader=new Image;
    var self=this;

    loader.onload=function () {
        self.currentEntry=null;
        if(entry.callback)
            entry.callback(entry.url,entry.index,entry.loader);
        if(self.queue.length>0)
            self.start();
    };

    loader.onerror=function () {
        // If a load fails, keep the queue going!
        self.currentEntry=null;
        if(entry.onErrorCallback)
            entry.onErrorCallback(entry.url,entry.index,entry.loader);
        if(self.queue.length>0)
            self.start();
    };

    this.currentLoader=loader;
    loader.src=entry.url;
};
// Since this script is not loaded by System.Web.Handlers.ScriptResourceHandler
// invoke Sys.Application.notifyScriptLoaded to notify ScriptManager 
// that this is the end of the script.
if(typeof (Sys)!=='undefined') Sys.Application.notifyScriptLoaded();